<?php
/////////////////////////////////////////////////////////////////////////////
// 这个文件是 网城创想多用户商城 项目的一部分
//
// Copyright (c) 2007 - 2008 www.shopnc.net
//
// 要查看完整的版权信息和许可信息，请查看源代码中附带的 COPYRIGHT 文件，
// 或者访问 http://www.shopnc.net/ 获得详细信息。
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : index.php   FILE_PATH : D:\webroot\mulitishop\store\index.php
 * ....商铺首页面
 *
 * @copyright Copyright (c) 2007 - 2007 www.shopnc.net 
 * @author 网城创想多用户商城开发团队 php_netproject@yahoo.com.cn
 * @package 
 * @subpackage 
 * @version Fri Sep 14 15:21:19 CST 2007
 */

require_once("../global.inc.php");

class StoreIndex extends CommonFrameWork{
	/**
	 * 商铺宝贝分类对象
	 *
	 * @var obj
	 */
	var $obj_category;
	/**
	 * 商铺友情链接
	 *
	 * @var obj
	 */
	var $obj_link;
	/**
	 * 商铺留言对象
	 *
	 * @var obj
	 */
	var $obj_message;
	/**
	 * 商品对象
	 *
	 * @var obj
	 */
	var $obj_product;
	
	
	
	function main(){
		//初始化店铺信息
		$this->ifStore();
		if ($this->member_type != 1){
			//如果不是商铺是会员的话跳转到会员信息页面
			$this->redirectPath("common","store/userinfo.php?userid=" . $this->_input['userid'],"");
		}
		/**
		 * 创建商铺宝贝分类对象
		 */
		if (!is_object($this->obj_category)){
			require_once("shopproductcategory.class.php");
			$this->obj_category = new ShopProductCategoryClass();
		}
		/**
		 * 创建商铺留言对象
		 */
		if (!is_object($this->obj_message)){
			require_once("shopmessage.class.php");
			$this->obj_message = new ShopMessageClass();
		}
		/**
		 * 创建商铺友情链接对象
		 */
		if (!is_object($this->obj_link)){
			require_once("shoplink.class.php");
			$this->obj_link = new ShopLinkClass();
		}
		/**
		 * 创建商品对象
		 */
		if (!is_object($this->obj_product)){
			require_once("product.class.php");
			$this->obj_product = new ProductClass();
		}
		/**
		 * 初始化分页类
		 */
		require_once("commonpage.class.php");
		$obj_page = new CommonPage();

		$shop_array = $this->storeBaseInfo();    //店铺基本信息

		/**
		 * 设置店铺模板路径
		 */
		if ($shop_array['templates'] == ''){
			$this->setsubtemplates("store");
		}else{
			$this->setStoreTemplates($shop_array['templates']);
		}

		/**
		 * 语言包
		 */
		$this->getlang("shop");

		$category_array = $this->obj_category->getCategory($this->_input['userid'],$page);        //店铺商品分类

		$link_array = $this->obj_link->getLink($this->_input['userid'],$page);       //店铺友情连接

		//$message_array = $this->obj_message->getLimitMessage($this->_input['userid'],3);       //店铺前3条留言

		/**
		 * 实例化商品订单类
		 */
		if (!is_object($this->obj_product_order)){
			require_once("order.class.php");
			$this->obj_product_order = new ProductOrderClass();
		}
		/**
		 * 更新到期团购商品订单状态
		 */
		$group_product_order_tobe_end_array = $this->obj_product_order->updateProductOrderInCondition();
		/**
		 * 更新到期商品状态
		 */
		$product_tobe_end_array = $this->obj_product->updateProductInCondition();
		
		/**
		 * 宝贝查询条件
		 */
		$obj_condition['key'] = $this->_input['keyword'];
		$obj_condition['keygenre'] = $this->_input['searchtype'];
		$obj_condition['member'] = $this->_input['userid'];
		$obj_condition['p_class_id'] = $this->_input['classid'];

		$obj_page->pagebarnum(10);
		switch ($this->_input['list']){
			case "end":
				$obj_condition['order'] = 1;
				$obj_condition['sorttype'] = 1;
				$obj_condition['state'] = 1;
				break;
			case "new":
				$obj_condition['order'] = 3;
				$obj_condition['state'] = 1;
				break;
			default:
				$obj_condition['order'] = 1;
				$obj_condition['sorttype'] = 1;
				$obj_condition['state'] = 1;
				break;
		}
		/**
		 * 按价格排序
		 */
		if($this->_input['price'] == "down"){
			$obj_condition['order'] = 2;
			$obj_condition['sorttype'] = 0;
		}elseif($this->_input['price'] == "up"){
			$obj_condition['order'] = 2;
			$obj_condition['sorttype'] = 1;
		}
		
		$product_array = $this->obj_product->getProductList($obj_condition, $obj_page);   //商铺所有的商品
		$page_list = $obj_page->show(1);
		
		for($i=0;$i<count($product_array);$i++){
			$left_time = $product_array[$i]['p_end_time'] - time();
			$product_array[$i]['left_days'] = intval($left_time / (24*60*60));
			$product_array[$i]['left_hours'] = intval(($left_time % (24*60*60)) / (60*60));
			$product_array[$i]['left_minutes'] = intval((($left_time % (60*60))) / 60);
			$j = 0;
		}
		
		$obj_recommended_condition['member'] = $this->_input['userid'];
		$obj_recommended_condition['store_recommended'] = 1;
		$product_store_recommended = $this->obj_product->getProductList($obj_recommended_condition, $obj_recommended_page);
		
		$this->output('userid',   $this->_input['userid']);     //输出店主ID
		$this->output('classid',   $this->_input['classid']);     //输出店铺商品分类ID
		$this->output('product_array',   $product_array);     //输出商铺所有的商品
		$this->output('product_count',   count($product_array));     //输出商铺商品总数
		$this->output("shop_recommended_product_array", $product_store_recommended);	//输出店铺推荐商品
		$this->output('message_array',   $message_array);     //输出商铺留言
		$this->output('category_array',   $category_array);     //输出商铺分类
		$this->output('link_array',   $link_array);     //输出商铺友情连接
		$this->output("page_list", $page_list);
		$this->showpage("store_index");
	}
}
$store = new StoreIndex();
$store->main();
unset($store);
?>